# Keybindings
bindkey -v
bindkey '^y' autosuggest-accept
bindkey '^p' history-search-backward
bindkey '^n' history-search-forward
bindkey '^[w' kill-region

[[ -r $XDG_DATA_HOME/zsh-plug/znap/znap.zsh ]] ||
    git clone --depth 1 -- https://github.com/marlonrichert/zsh-snap.git $XDG_DATA_HOME/zsh-plug/znap
source $XDG_DATA_HOME/zsh-plug/znap/znap.zsh

# `znap prompt` makes your prompt visible in just 15-40ms!
znap prompt sindresorhus/pure

# # `znap source` starts plugins.
# znap source marlonrichert/zsh-autocomplete
#
# # `znap eval` makes evaluating generated command output up to 10 times faster.
# znap eval iterm2 'curl -fsSL https://iterm2.com/shell_integration/zsh'
#
# # `znap function` lets you lazy-load features you don't always need.
# znap function _pyenv pyenv "znap eval pyenv 'pyenv init - --no-rehash'"
# compctl -K    _pyenv pyenv
#
# # `znap install` adds new commands and completions.
# znap install aureliojargas/clitest zsh-users/zsh-completions

znap source zsh-users/zsh-syntax-highlighting
znap source zsh-users/zsh-completions
znap source zsh-users/zsh-autosuggestions
znap source Aloxaf/fzf-tab

# # Load completions
# autoload -Uz compinit && compinit

# History
HISTSIZE=5000
HISTFILE=~/.cache/zsh/history
SAVEHIST=$HISTSIZE
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups

# Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'ls --color $realpath'

# Aliases
alias sudo='doas'
alias g='lazygit'
alias ls='eza'
alias la='eza -lag'
alias ll='eza -lg'
alias xi='doas xbps-install'
alias xq='xbps-query'
alias xr='doas xbps-remove'
alias yv='pipe-viewer --api=auto'
alias cp='cp -v'
alias mv='mv -v'
alias rm='rm -iv'
alias v='nvim'
alias vl='NVIM_APPNAME=nvim-lazyvim nvim'
alias vk='NVIM_APPNAME=nvim-kickstart nvim'
alias L='ls -la'
alias nnn='nnn -eU'
alias cl='clear'
alias grep='grep --color'
alias mbsync="mbsync -c $MBSYNCRC"
alias i="doas xbps-install -S"
alias u="i; doas xbps-install -u xbps; doas xbps-install -u"
alias q="xbps-query -Rs"
alias r="doas xbps-remove -R"
alias tmate='tmate -a ~/.ssh/authorized_keys -f ~/.config/tmate/tmate.conf new-session -s TMATE'

function cdf() {
	cd "$(find . -type d | fzf)" || exit
}

function vif() {
	vim "$(find . -type f | fzf)" || exit
}

# Shell integrations
eval "$(fzf --zsh)"
eval "$(zoxide init --cmd cd zsh)"
